<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Home</title>
    <link rel="stylesheet" th:href="@{static/css/layui.css}">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">运动会管理系统</div>
        <!-- 头部区域（可配合layui已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">

        </ul>
        <ul class="layui-nav layui-layout-right">
            <div th:if="${session.user}">
                <li class="layui-nav-item">
                    <a href="javascript:;">
                        <i class="layui-icon layui-icon-user" style="font-size: 15px"></i>
                        <span th:text="${session.user.getNum()}">unknown</span>
                    </a>
                    <dl class="layui-nav-child">
                        <dd th:if="${session.user.getIdentity().equals('2')}"><a th:href="@{userinfo}">基本资料</a></dd>
                        <dd><a th:href="@{/toPage(url=rePassword)}">修改密码</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item"><a href="user/logout">退出</a></li>
            </div>
            <div th:unless="${session.user}">
                <li class="layui-nav-item"><a th:href="@{/toPage(url=login)}">登录</a></li>
            </div>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree layui-inline" lay-filter="test" style="margin-right: 10px;">
                <li class="layui-nav-item"><a href="/sports">主页</a></li>
                <li class="layui-nav-item layui-nav-itemed">
                    <a href="javascript:;">当前赛况</a>
                    <dl class="layui-nav-child">
                        <dd><a th:href="@{/toPage(url=scoreSituation)}">田赛</a></dd>
                        <dd><a th:href="@{/toPage(url=scoreSituationJ)}">径赛</a></dd>
                    </dl>
                </li>
                <div th:if="${session.user}">
                    <li class="layui-nav-item" th:if="${session.user.getIdentity().equals('2')}"><a th:href="@{/toPage(url=signup)}">我要报名</a></li>
                    <li class="layui-nav-item" th:if="${session.user.getIdentity().equals('2')}"><a th:href="@{/toPage(url=myRegistration)}">我的报名</a></li>
                    <li class="layui-nav-item layui-nav-itemed" th:if="${session.user.getIdentity().equals('0') || session.user.getIdentity().equals('1')}">
                        <a href="javascript:;">上传成绩</a>
                        <dl class="layui-nav-child">
                            <dd><a th:href="@{/toPage(url=scoreEntryT)}">田赛</a></dd>
                            <dd><a th:href="@{/toPage(url=scoreEntryJ)}">径赛</a></dd>
                        </dl>
                    </li>
                    <li class="layui-nav-item" th:if="${session.user.getIdentity().equals('1')}"><a th:href="@{/toPage(url=registrationReview)}">报名审核</a></li>
                    <li class="layui-nav-item" th:if="${session.user.getIdentity().equals('1')}"><a th:href="@{/toPage(url=perManagement)}">人员管理</a></li>
                    <li class="layui-nav-item" th:if="${session.user.getIdentity().equals('1')}"><a th:href="@{/toPage(url=noticeManage)}">公告管理</a></li>
                    <li class="layui-nav-item" th:if="${session.user.getIdentity().equals('1')}"><a th:href="@{/toPage(url=volunteer)}">志愿者名单</a></li>
                    <li class="layui-nav-item" th:if="${session.user.getIdentity().equals('1')}"><a th:href="@{/toPage(url=projectManage)}">项目</a></li>
                </div>
            </ul>
        </div>
    </div>

    <div class="layui-body">
        <!-- 内容主体区域 -->

        <div class="layui-row">
            <div class="layui-col-md4 layui-col-md-offset5">
                <h1 style="height: 70px;">公告管理</h1>
            </div>
        </div>

        <div class="layui-row">
            <table id="notice" lay-filter="notice"></table>
        </div>

    </div>

</div>

<script th:src="@{static/layui.js}"></script>
<script th:src="@{static/jquery.js}"></script>

<!--控制菜单展开-->
<script>
    layui.use('element', function () {
        var element = layui.element;
        //监听导航点击
        element.on('nav(test)', function (elem) {

        });
    });
</script>

<script>
    layui.use('table', function () {
        var table = layui.table;
        //执行一个 table 实例
        table.render({
            elem: '#notice'
            , url: 'notice/findAllNoticeInfo' //数据接口
            , title: '管理员表'
            ,limit: 20
            , toolbar: 'default' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            , page: true //开启分页
            , cols: [
                [ //表头
                    {type: 'checkbox', fixed: 'left'}
                    ,{field: 'noticeId', title: 'ID', width: 100, fixed: 'left', sort: 'true'}
                    , {field: 'noticeDate', title: 'Date', width: 181}
                    , {field: 'noticeTitle', title: 'Title', width: 818}
                    , {field: 'noticeAuthor', title: 'Author', width: 100}

                ]
            ]
        });

        //监听头工具栏事件
        table.on('toolbar(notice)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id)
                , data = checkStatus.data; //获取选中的数据
            switch (obj.event) {
                case 'add':
                    window.location.href = "/sports/toPage?url=edit_announcement";
                    break;
                case 'update':
                    layer.msg('本表不支持编辑操作');
                    break;
                case 'delete':
                    if (data.length === 0) {
                        layer.msg('请选择一行');
                    } else {
                        var s = [];
                        for (let i = 0; i < data.length; i++) {
                            s[i] = checkStatus.data[i].noticeId;
                        }
                        layer.alert("确认要删除id为"+s+"的公告？", function(){
                            $.post('notice/delete', {id: s}, function (result) {
                                if (result == 'success') {
                                    window.location.reload();
                                } else {
                                    layer.alert("删除失败")
                                }
                            }, "text");
                        });
                    }
                    break;
            }
            ;
        });

        //监听行工具事件
        table.on('tool(notice)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'detail') {
                layer.msg('查看操作');
            } else if (layEvent === 'more') {
                //下拉菜单
                dropdown.render({
                    elem: this //触发事件的 DOM 对象
                    , show: true //外部事件触发即显示
                    , data: [{
                        title: '编辑'
                        , id: 'edit'
                    }, {
                        title: '删除'
                        , id: 'del'
                    }]
                    , click: function (menudata) {
                        if (menudata.id === 'del') {
                            layer.confirm('真的删除行么', function (index) {
                                obj.del(); //删除对应行（tr）的DOM结构
                                layer.close(index);
                                //向服务端发送删除指令
                            });
                        } else if (menudata.id === 'edit') {
                            layer.msg('编辑操作，当前行 ID:' + data.id);
                        }
                    }
                    , style: 'margin-left: -50px; box-shadow: 1px 1px 10px rgb(0 0 0 / 12%);' //设置额外样式
                })
            }
        });


    });
</script>

</body>
</html>
